<template>
    <page-box class="custom-page-box">
        <template v-slot:header>
            <ask-breadcrumb>
                <template v-for="(item, index) in $getBreadCrumbsName('/module-manage/town-home')">
                    <ask-breadcrumb-item :key="index" v-if="item.path" :to="'/' + item.path">{{ item.meta.title }}</ask-breadcrumb-item>
                    <ask-breadcrumb-item :key="index" v-else>{{ item.meta.title }}</ask-breadcrumb-item>
                </template>
                <ask-breadcrumb-item>我填报的</ask-breadcrumb-item>
            </ask-breadcrumb>
        </template>
        <page-search>
            <page-search-column class="fixed-column">
                <page-search-item>
                    <el-input class="pbb__search-input" v-model="form.name" placeholder="请输入表单名称"></el-input>
                </page-search-item>
                <page-search-item>
                    <el-button
                        type="primary"
                        class="pbb__search-btn"
                        @click="getTable()"
                    >
                        查询
                    </el-button>
                </page-search-item>
            </page-search-column>
        </page-search>
        <div class="task-manage-container">
            <el-table
                v-show="tableData.length"
                class="pbb__table"
                header-cell-class-name="pbb__table-thead"
                cell-class-name="pbb__table-thead-cell"
                row-class-name="pbb__table-thead-row"
                :data="tableData"
                style="width: 100%;height: 100%;background: #fff;overflow-y: auto;">
                <el-table-column
                    label="序号"
                    align="center"
                    type="index"
                    width="60">
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="表单名称">
                </el-table-column>
                <el-table-column
                    prop="createTime"
                    label="最新填报时间">
                </el-table-column>
                <el-table-column
                    prop="count"
                    label="填报数">
                </el-table-column>
                <el-table-column
                    label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" @click="toDetail(scope.row)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <ask-empty-text
                style="min-height: 400px;"
                v-if="tableData.length === 0">
            </ask-empty-text>
        </div>
        <template v-slot:footer v-if="total > 0">
            <pagination :total="total" :page.sync="pageIndex" :limit.sync="pageSize" @pagination="getTable"/>
        </template>
    </page-box>
</template>

<script lang="ts">
import { Component, Mixins } from "vue-property-decorator";
import UpLoadNormal from "@/components/upload-normal/index.vue";
import DownLoadTemplateUpLoadMixins from "./mixins";

@Component({
    name: "DeclareCollectionTaskNotAlive",
    components: {
        UpLoadNormal
    }
})
export default class DeclareCollectionTask extends Mixins(DownLoadTemplateUpLoadMixins) {
    form: any = {
        name: "",
        department: "",
        taskTime: "",
        status: ""
    }

    // 数据总数
    total = 0;
    // 每页数量
    pageSize = 10;
    // 当前页码
    pageIndex = 1;
    // 表格数据
    tableData = []

    created() {
        this.getTable();
    }

    // 查询表格
    async getTable() {
        const res = await this.$server["moduleManage/fillForm/list"]({
            data: {
                pageSize: this.pageSize,
                currentPage: this.pageIndex,
                keyword: this.form.name || undefined
            }
        });
        if (res.data.code === 200) {
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
        } else {
            this.$message.error(res.data.message || "接口请求错误!");
        }
    }

    // 导入
    importRow(row: any) {
        this.currentFormId = row.formId;
    }

    // 查看
    toDetail(row: any) {
        this.$router.push({
            name: "TownFillInFormDetail",
            query: {
                id: row.id,
                formId: row.formId,
                assigneeId: row.assigneeId,
                name: row.name,
                description: row.description,
                descriptionType: row.descriptionType
            }
        });
    }
}
</script>
<style lang="scss" scoped>
.task-manage-container {
    height: calc(100% - 50px);
}
</style>
